<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>更改密码</title>
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/admin.css">
</head>
<body>

<form class="layui-form" action="" style="margin:0 auto;width:300px;">
    <div class="layui-form-item" >
        <label class="layui-form-label">当前用户</label>
        <div class="layui-input-block">
            <label class="layui-form-label" id="nickname1">无</label>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-block">
            <input type="password" name="origin" lay-verify="required" lay-verify="pass" placeholder="请输入原密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newpwd" lay-verify="required" placeholder="请输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">确认新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newpwd2" lay-verify="required" placeholder="再次输入新密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <div class="layui-input-block">
        <a class="layui-btn" lay-submit="" lay-filter="change">提交</a>
        </div>
    </div>
</form>

<script src="../layui/layui.js"></script>
<script>
layui.use(['jquery','form','layer'],function () {
    var $ = layui.jquery;
    $('#nickname1').html($("#nickname",parent.document).text());
    var form = layui.form;
    var origina='';
    $.ajax("/getUser.manager",{
        type:'post',
        success: function(dataa, status, response) {
            // data = JSON.parse(data); //如果后台没有设置数据格式为json，可以转成json对象
            console.info('aaaaaaaaaaa')
            origina = dataa.password;

        },
        error: function(data, status, response) {
        }
    });
    form.on('submit(change)', function(data) {
        console.info('aaaa');

        console.info(data.field.origin);
        console.info(origina);
        if(data.field.origin !=origina){
            layer.msg('原密码不正确');
            return ;
        }
        if(data.field.newpwd != data.field.newpwd2){
            layer.msg('两次密码不一样');
            return ;
        }
        $.ajax("/changePwd.manager", {
            type: 'post',
            data: {
                newpwd:data.field.newpwd
            },
            // contentType: 'application/json',
            success: function (data) {
                // console.info(data);
                if (data.state == 1) {
                    layer.closeAll();
                    layer.msg('修改成功');
                } else if(data.state == -1){
                    layer.msg(data.msg);
                }
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('修改失败');
            }
        })
    });

})
</script>
</body>
</html>